from .filters import ProjectFilter
from main.alarm.models import Project
from .serializers import ProjectSerializer, ProjectCreateUpdateSerializer
from utils.viewset import CustomModelViewSet
from utils.permission import CustomPermission


class ProjectModelViewSet(CustomModelViewSet):
    """
    项目管理 的CRUD视图
    """
    queryset = Project.objects.all()
    serializer_class = ProjectSerializer  # 序列化器
    create_serializer_class = ProjectCreateUpdateSerializer  # 创建/更新时的列化器
    update_serializer_class = ProjectCreateUpdateSerializer  # 创建/更新时的列化器
    filter_class = ProjectFilter  # 过滤器
    update_extra_permission_classes = (CustomPermission,)  # 判断用户是否有这条数据的权限
    destroy_extra_permission_classes = (CustomPermission,)  # 判断用户是否有这条数据的权限
    create_extra_permission_classes = (CustomPermission,)  # 判断用户是否有这条数据的权限
    search_fields = ('name',)  # 搜索
    ordering = ['create_datetime']  # 默认排序
